//
//  DebitAttentionView.swift
//  IDF
//
//  Created by 陈徐挺 on 2018/4/9.
//  Copyright © 2018 Jesse.chen. All rights reserved.
//

import UIKit
import Reusable

class DebitAttentionView: UIView, NibOwnerLoadable {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    var record: Record!
    @IBOutlet weak var label_1: UILabel!
    @IBOutlet weak var label_2: UILabel!
    @IBOutlet weak var label_3: UILabel!
    @IBOutlet weak var label_4: UILabel!
    @IBOutlet weak var label_5: UILabel!
    @IBOutlet weak var label_6: UILabel!
    @IBOutlet weak var label_7: UILabel!
    @IBOutlet weak var label_8: UILabel!
    @IBOutlet weak var label_9: UILabel!
    @IBOutlet weak var label_10: UILabel!
    @IBOutlet weak var repaymentBtn: UIButton!
    @IBOutlet weak var extendBtn: UIButton!
    
    
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.loadNibContent()
    }
    
    func setView() {
        label_2.text = "\(record.debitMoney!)"
        label_3.text = "\(record.payBackMoney!)"
        label_4.text = "\(record.repaymentTime!)"
        label_5.text = "\(record.debitPeroid!)"
        if record.auditInfo! != "" {
//            label_7.text = "Cause of failure :"
            label_7.text = "information :"
            label_8.text = "\(record.auditInfo!)"
            label_9.isHidden = true
            label_10.isHidden = true
        }
        repaymentBtn.isHidden = true
        extendBtn.isHidden = true
        switch record.status! {
        case -2:
            label_1.text = "Repayment failure"
            repaymentBtn.isHidden = false
            extendBtn.isHidden = false
        case 1:
            label_1.text = "Reminders"
            repaymentBtn.isHidden = false
            extendBtn.isHidden = false
        case 4:
            label_1.text = "Overdue"
            label_6.text = "Overdue days"
            label_5.text = "\(record.overdueDay!)"
            repaymentBtn.isHidden = false
            extendBtn.isHidden = false
        case -1:
            label_1.text = "Audit failure"
        case 0:
            label_1.text = "Auditing"
        case 2:
            label_1.text = "Repaid audit"
        case 3:
            label_1.text = "Repaid"
        case 5:
            label_1.text = "Through audit"
        default:
            break
        }
    }
    @IBAction func closeClick(_ sender: UIButton) {
        removeFromSuperview()
    }
    @IBAction func repaymentClick(_ sender: UIButton) {
        let next: RepaymentViewController = initViewContollerWithStoryboard(storyboardName: "Record", storyboardId: "repaymentViewController")
        next.record = record
        nowNavgationController.pushViewController(next, animated: true)
        removeFromSuperview()
    }
    @IBAction func extendClick(_ sender: UIButton) {
        let next: RepaymentViewController = initViewContollerWithStoryboard(storyboardName: "Record", storyboardId: "repaymentViewController")
        next.record = record
        next.isExtend = true
        nowNavgationController.pushViewController(next, animated: true)
        removeFromSuperview()
    }
    
}
